<?php
$tbl = 
<<<VSTABLEJS
<script language="javascript">
	var cBg;
	var vFr;
	var cId;
	var horizontal_offset = 0;
	function __vstable_change_cell_style__(newColor)
	{
		objT = event.srcElement;
		if ( objT.tagName != "TD" )
			return false;
		newColor = newColor.split(",");
		if ( event.type == "mouseover" )
		{
			cBg = objT.style.backgroundColor;
			cFr = objT.style.color;
			
			objT.style.backgroundColor = newColor[0];
			objT.style.color = newColor[1];
		}
		else
		{
			objT.style.backgroundColor = cBg;
			objT.style.color = cFr;
		}
	}

	function __vstable_showInput(id, event) 
	{
		cId = id;
		txt  = document.getElementById(id);
		txt1 = document.getElementById("__txtData");
		
		if ( !document.all["func_" + id] )
			txt1.value = txt.innerHTML;
		else
		{
			objF = document.getElementById("func_" + id);
			txt1.value = objF.value;
		}
		//txt.innerHTML = "";
		
		obj = document.getElementById("__inputArea");
		obj.style.left=obj.style.top=-500
		obj.x = __vstable_getposOffset(event,"left");
		obj.y = __vstable_getposOffset(event,"top");
		obj.style.left=obj.x;
		obj.style.top=obj.y;
		txt1.style.width = txt.width;
		txt1.style.height = txt.height;
		obj.style.display = "";
		txt1.focus();
	}
	
	function __vstable_IsNumeric(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
		
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
				return IsNumber;
			}
		}
		
		return IsNumber;
	}
	
	function __vstable_replacePoint(sText)
	{
		while ( sText.indexOf(".") != -1 )
				sText = sText.replace(".","");
		return sText;
	}
	
	function __vstable_trim(sText)
	{
		while ( sText.indexOf(" ") != -1 )
				sText = sText.replace(" ","");
		return sText;
	}
	
	function __vstable_ltrim(sText)
	{
		while ( sText.charAt(0) == " " )
				sText = sText.replace(" ","");
		return sText;
	}
	
	function __vstable_addPoint(sText)
	{
		sText = __vstable_replacePoint(sText);
		var ret = "";
		var no = 0;
		for ( i=sText.length-1; i >= 0; i-- )
		{
			if ( no != 3 )	//chua co add .
			{
				if ( ret == "" )
					ret = sText.charAt(i);
				else
					ret = sText.charAt(i) + ret;
			}
			else	//add .
			{
				ret = sText.charAt(i) + "." + ret;
				no = 0;
			}	
			no++;
		}
		return ret;			
	}
	
	function __vstable_savedata()
	{
		obj = document.getElementById(cId);
		txt = document.getElementById("__txtData");	
		objHidden = document.getElementById("data_" + cId);
						
		val = __vstable_ltrim(txt.value);
		
		/* co su dung function */
		if ( val.charAt(0) == "=" )
		{
			val = __vstable_trim(val);
			sP = val.indexOf("(");
			fName = val.substring(1,sP);
			fName = fName.toUpperCase();
			params = val.substring(sP+1,val.length-1);
			params = params.split(",");
			cell1 = params[0].split(":");
			cell2 = params[1].split(":");
			
			objc1 = document.getElementById("cell_" + cell1[0] + "_" + cell1[1]);
			objc2 = document.getElementById("cell_" + cell2[0] + "_" + cell2[1]);
			
			switch(fName)
			{
				case "ADD": case "+":
					tmp = __function_add(objc1.innerText,objc2.innerText);
					obj.innerHTML = tmp;
					objHidden.value = tmp;
					obj.innerHTML = __vstable_addPoint(obj.innerHTML);
					__vstable_createFunctionDiv(cId,val);
					break;
				case "MINUS": case "-":
					tmp = __function_minus(objc1.innerText,objc2.innerText);
					obj.innerHTML = tmp;
					objHidden.value = tmp;
					__vstable_createFunctionDiv(cId,val);
					obj.innerHTML = __vstable_addPoint(obj.innerHTML);
					break;
				case "MUL": case "*":
					tmp = __function_mul(objc1.innerText,objc2.innerText);
					obj.innerHTML = tmp;
					objHidden.value = tmp;
					obj.innerHTML = __vstable_addPoint(obj.innerHTML);
					__vstable_createFunctionDiv(cId,val);
					break;
				case "DIV": case "/":
					tmp = __function_div(objc1.innerText,objc2.innerText);
					obj.innerHTML = tmp;
					objHidden.value = tmp;
					obj.innerHTML = __vstable_addPoint(obj.innerHTML);
					__vstable_createFunctionDiv(cId,val);
					break;
				case "MOD": case "%":
					tmp = __function_mod(objc1.innerText,objc2.innerText);
					obj.innerHTML = tmp;
					objHidden.value = tmp;
					obj.innerHTML = __vstable_addPoint(obj.innerHTML);
					__vstable_createFunctionDiv(cId,val);
					break;
			}
		}
		else if ( val == "" )
		{
			if ( document.all["func_" + cId] )
			{
				objF = document.getElementById("func_" + cId);
				objF.value = "";
				txt1.value = "";
			}
			obj.innerHTML = value = "";
			objHidden.value = "";
		}
		else
		{
			if ( __vstable_IsNumeric(txt.value) )
				obj.innerHTML = __vstable_addPoint(txt.value);
			else
				obj.innerHTML = txt.value;
			objHidden.value = txt.value;		
		}		
		txt.value = "";
		cId = "";
		obj = document.getElementById("__inputArea");
		obj.style.display = "none";
	}
			
	function __vstable_closeInput()
	{
		obj = document.getElementById("__inputArea");
		obj.style.display = "none";
	}
			
	function __vstable_getposOffset(what, offsettype)
	{
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
		while (parentEl!=null){
			totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
			parentEl=parentEl.offsetParent;
		}
		return totaloffset;
	}

	function __vstable_clearbrowseredge(obj, dropmenuobj, whichedge)
	{
		var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
		if (whichedge=="rightedge")
		{
			var windowedge=ie && !window.opera? __vstable_iecompattest().scrollLeft+__vstable_iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
			dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
			if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
				edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
		}
		else
		{
			var windowedge=ie && !window.opera? __vstable_iecompattest().scrollTop+__vstable_iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
			dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
			if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
				edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
		}
		return edgeoffset;
	}
	
	function __vstable_createFunctionDiv(cellID,val)
	{
		var divblock=document.createElement("div");
		divblock.setAttribute("id", "func_" + cellID);
		divblock.setAttribute("value",val);
		document.body.appendChild(divblock);
	}
	
	function __function_add(v1, v2)
	{			
		v1 = __vstable_replacePoint(v1);
		v2 = __vstable_replacePoint(v2);
		
		tmp = (parseFloat(v1)+parseFloat(v2));
		return tmp;
	}
	
	function __function_minus(v1, v2)
	{			
		v1 = __vstable_replacePoint(v1);
		v2 = __vstable_replacePoint(v2);
		
		tmp = (parseFloat(v1)-parseFloat(v2));
		return tmp;
	}			
	
	function __function_mul(v1, v2)
	{			
		v1 = __vstable_replacePoint(v1);
		v2 = __vstable_replacePoint(v2);
		
		tmp = (parseFloat(v1)*parseFloat(v2));
		return tmp;
	}

	function __function_div(v1, v2)
	{			
		v1 = __vstable_replacePoint(v1);
		v2 = __vstable_replacePoint(v2);
		
		tmp = (parseFloat(v1)/parseFloat(v2));
		return tmp;
	}			

	function __function_mod(v1, v2)
	{			
		v1 = __vstable_replacePoint(v1);
		v2 = __vstable_replacePoint(v2);
		
		tmp = (parseFloat(v1)%parseFloat(v2));
		return tmp;
	}

	function __vstable_iecompattest()
	{
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}			
	
	function __vstable_detectEnter()
	{
		if ( event.keyCode == 13 )
			__vstable_closeInput();
	}
</script>
VSTABLEJS;
?>